package com.tianhui.consignortwofei.other.auth.stragety;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import androidx.annotation.Nullable;

import com.fgs.common.utils.FileUtil;
import com.tianhui.consignortwofei.mvp.model.enty.SelectPhotoInfo;
import com.tianhui.consignortwofei.other.auth.PictureStrategy;
import com.tianhui.consignortwofei.other.auth.inte.SelectPhotoCallback;
import com.tianhui.consignortwofei.other.auth.state.IPictureProcessState;
import com.tianhui.consignortwofei.utils.ApplicationUtil;


/**
 * @author fgs
 * @date 2021/5/17
 * @description
 **/
public abstract class BasePictureStrategy extends PictureStrategy {
    private SelectPhotoCallback pictureCallback;
    private Context context;

    @Override
    public int initTipImageId() {
        return 0;
    }

    @Override
    public void selectPhoto(Context context, SelectPhotoCallback callback) {
        pictureCallback = callback;
        this.context = context;
        showPictureDialog(context,callback);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK) {
            if (data != null) {
                String filePath = FileUtil.getSaveFile(ApplicationUtil.getContext()).getAbsolutePath();
                SelectPhotoInfo selectPhotoInfo = new SelectPhotoInfo();
                selectPhotoInfo.filePath = filePath;
                IPictureProcessState iPictureProcessState = getPictureProcessState();
                if (iPictureProcessState != null) {
                    iPictureProcessState.stateProcess(context, selectPhotoInfo, pictureCallback);
                } else {
                    pictureCallback.selectPhotoSuccess(selectPhotoInfo);

                }
            }
        }
    }
}
